<?php

include_once "function_xml_basic.php";

$root_path = "/MINI/MONITOR";

function GetXmlNetMonitorInfoList()
{
	global $root_path;
	$query_string = $root_path. "/NTOP";
        $key_array = array("Enabled", "Warning", "Dev","PassWd","Syslogd");
        return GetAttributList($query_string, $key_array);
}
/*
$ret_array = GetXmlIdsServerInfoList();
foreach ($ret_array as $i)
{
	print $i["Warning"];
	print $i["Ports"];
}
*/
function SetXmlNetMonitorInfo($in_array)
{
        global $root_path;
        $query_string = $root_path. "/NTOP[1]";

        EditAllAttrOfNode($query_string, $in_array);

	ApplySysNetMonitorConfig();
}

function ApplySysNetMonitorConfig()
{
	global $root_path;
 	
	$list = GetXmlNetMonitorInfoList();
	
	foreach ($list as $l)
	{
		$ret = $l;
		break;
	}
	
	$command = "/usr/local/bin/ntop ";
	$command_passwd = $command. " --set-admin-password=".$ret['PassWd']. " ;";
	
	$command_start = $command. " -u root -L -d --trace-level=".$ret['Warning']. " -i ". $ret['Dev']. ";";

	
	$command_kill = 'kill -9 `cat /var/run/ntop.pid` ; ';

	$command_rule_add = "/usr/local/bin/iptables -A ADMINRANGE -p tcp --dport 3000 -j ACCEPT;";
	$command_rule_del = "/usr/local/bin/iptables -D ADMINRANGE -p tcp --dport 3000 -j ACCEPT;";
	$command_string = $command_passwd. $command_start;
	
	//print $command_string;
	//print $command_kill;
	shell_exec ($command_kill);
	shell_exec($command_rule_del);

	if ($ret['Enabled'] == 1) // start
	{
		shell_exec($command_rule_add);
		shell_exec ($command_string);
	}
}

?>
